import {defineStore} from "pinia";
import {ref} from "vue";

export const useConnectionStore = defineStore('connections', () => {
    const connections = ref([]);
    function put(c) {
        remove(c);
        connections.value.push(c);
    }
    function remove(c) {
        let name = c.name;
        connections.value = connections.value.filter(x => x.name!== name);
    }
    function reversion(name,version) {
        let exist = connections.value.filter(x => x.name=== name);
        if(!!exist){
            exist.version = version;
        }
    }
    return {
        connections,
        put,
        remove,
        reversion,
    };
},{
    persist: {
        enabled: true
    }
});


